
from TextReaderImpl        import *
from FactoryImpl           import *
from GuiReaderImpl         import *
from StyleSheetsReaderImpl import *
from DesignerImpl          import *

class TextReader(TextReaderImpl):
    def __init__(self, controller):
        TextReaderImpl.__init__(self, controller)

class Factory(FactoryImpl):
    def __init__(self, controller):
        FactoryImpl.__init__(self, controller)

class GuiReader(GuiReaderImpl):
    def __init__(self, factory, parent):
        GuiReaderImpl.__init__(self, factory, parent)

class StyleSheetsReader(StyleSheetsReaderImpl):
    def __init__(self, other = None):
        StyleSheetsReaderImpl.__init__(self, other)

class Controller(object):
    def __init__(self):
        object.__init__(self)
        self.texts       = {}
        self.stylesheets = StyleSheetsReader()
        self.images      = []
        self.parent      = None

        if os.path.isfile("plugins/global_styles.xml"):
            self.stylesheets.parse("plugins/global_styles.xml")

        textReader = TextReader(self)
        textReader.parse("plugins/global_texts.xml")

        self.factory = Factory(self)
        self.factory.registerElements()

    def run(self, parent, name):
        self.parent = parent
        guiReader   = GuiReader(self.factory, parent)
        guiReader.parse("plugins/" + name + ".xml")

    def addText(self, tid, text):
        self.texts[tid] = text

    def getText(self, tid):
        try:
            return self.texts[tid]
        except:
            return "No Text!"

class Designer(DesignerImpl):
    def __init__(self):
        stylesheets = StyleSheetsReader()
        if os.path.isfile("plugins/global_styles.xml"):
            stylesheets.parse("plugins/global_styles.xml")

        root = Tkinter.Tk()
        root.title("PyXmlTkinter Designer")
        root.geometry('600x400+100+100')

        DesignerImpl.__init__(self, root, stylesheets)

if __name__ == "__main__":
    controller = Controller()
